import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToMany,
  JoinTable,
} from 'typeorm';
import { Posts } from './Posts';
@Entity('tags')
export class Tags {
  @PrimaryGeneratedColumn({
    type: 'int',
    name: 'id',
    comment: '主键ID',
  })
  id: number;
  @Column({
    type: 'varchar',
    name: 'name',
    nullable: false,
    unique: true,
    comment: 'tag名称',
  })
  name: string;
  //   manytomany 用来说明字段的关联关系 jointable需要指定这是关系的所有方
  @ManyToMany(
    type => Posts,
    posts => posts.tags,
  )
  @JoinTable({ name: 'tags_posts' })
  posts: Posts[];
}
